package com.xs.tool.juc;

import java.util.concurrent.Semaphore;

/// 线程信号量
public class SemaphoreHolder implements AutoCloseable {
    private final Semaphore semaphore;

    public SemaphoreHolder(Semaphore semaphore) throws InterruptedException {
        this.semaphore = semaphore;
        semaphore.acquire();
    }

    @Override
    public void close() {
        semaphore.release();
    }
}
